package com.ruoyi.websocket;

/**
 * @projectName: ruoyi
 * @package: com.ruoyi.websocket
 * @className: WebSocketConfig
 * @author: 徐源长
 * @description:
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Component
@Configuration
@EnableWebSocket
@CrossOrigin
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // /ws为WebSocket的服务端点
        registry.addHandler(new ChatWebSocketHandler(), "/ws")
                .setAllowedOrigins("*")
                .setAllowedOriginPatterns("GET", "POST", "PUT", "DELETE", "OPTIONS");
    }
}
